package com.dhnsoft.web.controller;

import com.dhnsoft.web.entity.Person;
import com.dhnsoft.web.service.Aservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;
import java.util.List;

/**
 * @author dhn
 * @version 1.0
 * @date 2023-08-26 10:41
 * @Desc
 */
@Controller
public class WelcomeController {

    @Autowired
    Aservice aservice;

    @GetMapping("wel")
    public String welcome(@RequestParam("name") String name, Model model){
        model.addAttribute("name",name);
        return "welcome";
    }

    @GetMapping("/list")
    public String list(Model model){
        List<Person> list = Arrays.asList(
            new Person(1L,"张三1","zs1@qq.com",15),
            new Person(2L,"张三2","zs2@qq.com",16),
            new Person(3L,"张三3","zs3@qq.com",17),
            new Person(4L,"张三4","zs4@qq.com",18),
            new Person(5L,"张三5","zs5@qq.com",19)
        );
        model.addAttribute("list",list);
//        int i = 1/0;
        return "list";
    }

    @GetMapping("/")
    public String index(){
        aservice.a();
        return "index";
    }
}
